
//转盘 start
function cirlce(obj, options) { //obj 为被转动 dom 
    //设置默认选项
    options = options || {};
    options.time = options.time || 5;              // 时间
    options.defaulTurns = options.defaulTurns || 10;// 默认要转的圈数
    options.offset = options.offset || 0;          // 偏移度数
    options.initAngle = options.initAngle || 0;    // 初始化角度
    options.easing = options.easing || Run.Tween.Quad.easeInOut;// 缓冲

    if (!obj) {
        throw "obj is undefined, can't cirlce!!!";
    }

    if (!options.areas_number) { // 奖项数 
        throw "areas_number is undefined, can't cirlce!!!";
    }

    Run.setRotateZ(obj, options.initAngle);

    var divide = 360 / options.areas_number; //每个奖品占的度数 
    var divide_2 = divide / 2;
    var offset = Mathrandom(-options.offset, options.offset) / 1.5; //处理 偏移度数
    //console.log("offset " + offset )

    var divide_2Arr = [];  //存放每块扇形中间的角度值 + offset
    for (var i = 0; i < options.areas_number; i++) {
        divide_2Arr.push(i * divide + divide_2 + offset);
    }
    var len = divide_2Arr.length;

    this.start = function (_target) {
        var finalTarget; //最终中奖目标
        if (_target || _target == 0) {
            finalTarget = _target;
        } else if (options.target || options.target == 0) {
            finalTarget = options.target;
        } else {
            throw "target is undefined, can't cirlce!!!";
        }

        if (finalTarget >= len) {
            throw "中奖目标应该小于 " + len + ", can't cirlce!!!";
        }

        if (options.offset >= divide_2) {
            throw "偏移度数应该小于" + divide_2 + ", can't cirlce!!!";
        }

        var getRotation = divide_2Arr[finalTarget];
        var defaulTurns = options.defaulTurns * 360; // 圈数 * 360
        var maxRotation = defaulTurns + getRotation;// 最大旋转度数

        Run.to(obj, {
            time: options.time,
            rotationZ: maxRotation,
            easing: options.easing,
            onUpdate: function (n) {
                options.onUpdate && options.onUpdate(n);
            },
            onEnd: function () {
                var yyy = maxRotation % defaulTurns;
                Run.setRotateZ(obj, yyy);
                options.onEnd && options.onEnd();
            }
        });
    };

    this.stop = function (obj) {
        Run.stop(obj);
    };

    function Mathrandom(n, m) {
        return parseInt(n + Math.random() * (m - n));
    }

}
//转盘 end


